def factors(num):
    factor = [1]
    for i in range(2, int(pow(num, 0.5))):
        if num % i == 0:
            factor.append(i)
            factor.append(num // i)
    return sum(factor)


if __name__ == '__main__':
    amicable = []
    for i in range(1, 10001):
        t = factors(i)
        if i == factors(t) and i != t:
            amicable.append(i)
            amicable.append(t)
    print(sum(set(amicable)))
